﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace QLDHS
{
    public partial class FrmMain : Form
    {
        OleDbConnection connect = Program.GetConnection();
        public FrmMain()
        {
            InitializeComponent();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {

        }
        private void CloseAllChildForms()
        {
            foreach (Form frm in this.MdiChildren)
            {
                frm.Close();
            }
        }
        private void đăngNhậpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    connect.Open();
            //    string user = txt_user.Text;
            //    string _pass = txt_pass.Text;
            //    // where _username='" + user + "' and  _password='" + _pass + "'"
            //    OleDbCommand cmd = new OleDbCommand("SELECT * FROM _user ", connect);

            //    OleDbDataReader reader = cmd.ExecuteReader();
            //    while (reader.Read())
            //    {
            //        if (user.Equals(reader[1].ToString()))
            //        {
            //            lb_thongbao.Text = "OK";
            //        }
            //    }

            //}
            //catch (Exception ex)
            //{
            //    lb_thongbao.Text = ex + "";
            //}
            //finally
            //{

            //}
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            menuStrip1.Visible = false;
            
            Login l = new Login();
            l.MdiParent = this;
            l.FormClosed += new FormClosedEventHandler(l_Fromclose);
            l.Show();
        }
        void l_Fromclose(object sender, FormClosedEventArgs e)
        {
            Login s = sender as Login;
            int ch = s.Kt;
            if (s.Kt == 1)
                menuStrip1.Visible = true;
            else
            {
                menuStrip1.Visible = true;
                updateInfor_Menuitem.Visible = true;
        
            }
        }

        private void cậpNhậtThôngTinHọcKìToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

      

        private void cậpNhậtLớpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            //lb_tenphanemmen.Visible = false;
            
            //CapNhatLop updateLop = new CapNhatLop();
            //updateLop.TopLevel = false;
            //updateLop.MdiParent = this;
            //updateLop.Show();

            HSNS hs = new HSNS();
            hs.MdiParent = this;
            hs.Show();
        }

   

        private void timkiem_MenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
           
            lb_tenphanemmen.Visible = false;
            Search lpd = new Search();
          
            lpd.MdiParent = this;
            lpd.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult h = MessageBox.Show("Bạn có thật sự muốn thoát khỏi chương trình  ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
            if (h == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
        {

            menuStrip1.Visible = false;
            updateInfor_Menuitem.Visible = false;
         
            Login l = new Login();
            l.MdiParent = this;
            l.FormClosed += new FormClosedEventHandler(l_Fromclose);
            l.Show();
        }

        private void quảnLýLươngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            LUONG luong = new LUONG();
            luong.MdiParent = this;
            luong.Show();

        }

        private void QLKhenTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            KhenThuong kt = new KhenThuong();
            kt.MdiParent = this;
            kt.Show();
        }

        private void QLKLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            KyLuat kl = new KyLuat();
            kl.MdiParent = this;
            kl.Show();
        }

        private void QLQHGDToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            GIADINH gd = new GIADINH();
            gd.MdiParent = this;
            gd.Show();

        }

        private void QLQTCTToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            QuaTringCongtac qt = new QuaTringCongtac();
            qt.MdiParent = this;
            qt.Show();
        }

        private void QLPBToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            DonVi dv = new DonVi();
            dv.MdiParent = this;
            dv.Show();
        }

        private void QLCVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseAllChildForms();
            ChucVu cv = new ChucVu();
            cv.MdiParent = this;
            cv.Show();

        }

        
    }
}
